package com.cloud.rou.im.cluster.zk;

import com.cloud.rou.im.core.util.SingletonUtil;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

/**
 * <p></p>
 *
 * @author GaoShuangWen
 * @since 2019-11-08 21:20
 */
public class ZookeeperClientFactory {

    public static final String ZKADDRESS = "47.105.105.217:8088";

    private CuratorFramework curatorFramework;

    private ZookeeperClientFactory() {
        init();
    }

    private void init() {
        ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, 3, Integer.MAX_VALUE);
        CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(ZKADDRESS, retryPolicy);
        curatorFramework.start();
        this.curatorFramework = curatorFramework;
    }

    public static ZookeeperClientFactory getInstance() {

        return SingletonUtil.get(ZookeeperClientFactory.class);
    }

    public CuratorFramework getZkCli() {
        return this.curatorFramework;
    }

}
